<?php
/*
 * Author: NghiaTT
 * Date: 07-09-2011
 * Email:nghiatruong@vietnambiz.com
 */
require_once 'client'.EXT;

class Html extends Client {

	function __construct()
	{
		parent::__construct();		
        $this->load->library(array("form_validation","Message"));
		$this->load->helper(array('custom_string','form'));
		$this->load->model(array('html_model','home_model','questions_model'));	

		$this->data['support'] 				= $this->home_model->get_support();
		$this->data['questions']			= $this->home_model->get_questions(1);
		$this->data['products_best_sales']	= $this->home_model->get_all_products('best_sales',5);

	}
	//page gioi thieu
	function index()
	{
		$articles_info					= $this->html_model->get_articles_by_link('gioi-thieu');
		$this->data['articles_info'] 	= $articles_info;
		//meta tag
	    $this->data['title'] 			= get_title('[TITLE]',$articles_info != null ? $articles_info->title : "");
	    $this->data['description'] 		= get_description('[DESCRIPTION]',$articles_info != null ? $articles_info->title : "");
		$this->data['keywords'] 		= get_keywords('[KEYWORDS]',$articles_info != null ? $articles_info->title : "");	    
		//end meta tag
		
		$this->data['tpl_file']		=	'html/index';
		$this->load->view('layout/default',$this->data);
	}
	//page ho tro su dung
	function hotro()
	{
		$articles_info					= $this->html_model->get_articles_by_link('ho-tro-su-dung');
		$this->data['articles_info'] 	= $articles_info;
		//meta tag
	    $this->data['title'] 			= get_title('[TITLE]',$articles_info != null ? $articles_info->title : "");
	    $this->data['description'] 		= get_description('[DESCRIPTION]',$articles_info != null ? $articles_info->title : "");
		$this->data['keywords'] 		= get_keywords('[KEYWORDS]',$articles_info != null ? $articles_info->title : "");	    
		
		$this->data['tpl_file']		=	'html/index';
		$this->load->view('layout/default',$this->data);
	}
	
	//page thong tin lien he
	function lienhe()
	{
		if ($this->input->server('REQUEST_METHOD') === 'POST')
        {        	
        	$this->form_validation->set_message('required', '%s');
            $this->form_validation->set_message('valid_email', '%s');
            $this->form_validation->set_rules("txtContactName","Họ tên","required");            
            $this->form_validation->set_rules("txtContactAddress","Địa chỉ","required");
            $this->form_validation->set_rules("txtContactEmail","Email","required|valid_email");
            $this->form_validation->set_rules("txtContactPhone","Điện thoại","required");
            $this->form_validation->set_rules("txtContactContent","Nội dung","required");
                                  
            if($this->form_validation->run() === TRUE)
            {            	
            	 $fullname			=	strip_tags($this->input->post('txtContactName'));                 
            	 $email          	=	strip_tags($this->input->post('txtContactEmail'));
                 $address			=	strip_tags($this->input->post('txtContactAddress'));
                 $phone				=	strip_tags($this->input->post('txtContactPhone'));                 
                 $content           = 	strip_tags($this->input->post('txtContactContent'));
                 $id_customer		=  	0;
                         		 	                                                  		
                 if($this->questions_model->check_email_customers($email)==FALSE)
                 {
	                 $data_customers = array(
	                 	'fullname'		=> $fullname,
	                 	'email'			=> $email,
	                 	'address'		=> $address,
	                 	'telephone'		=> $phone,
	                 	'date_create'	=> date('Y-m-d H:i:s'),
	                 	'active'		=> 'yes'
	                 );
	                 $this->db->insert('customers', $data_customers);
		             $id_customer = $this->db->insert_id();
                 }
                 else
                 {
                 	$customer_info = $this->questions_model->get_customers_info_by_email($email);
	                $id_customer   = $customer_info->id;  
                 }
                                         		 
                  //Insert data to table contacts with type = contact
                  $data = array(
                  	'id_customer'		=> $id_customer,                  	
                  	'contents'			=> $content,
                  	'date_create'		=> date('Y-m-d H:i:s')                  	                
                  );
                  $re = $this->db->insert('contacts', $data);
                  if($re == TRUE)
                 {
                 	$this->message->add("success",'<li class=success><p>Bạn đã gửi ý kiến thành công! Xin cảm ơn!<META HTTP-EQUIV=refresh CONTENT=5;URL="'.base_url().'"></p></li>');
                 }                 
            }
        }
        
		$articles_info					= $this->html_model->get_articles_by_link('thong-tin-lien-he');
		$this->data['articles_info'] 	= $articles_info;
		//meta tag
	    $this->data['title'] 			= get_title('[TITLE]',$articles_info != null ? $articles_info->title : "");
	    $this->data['description'] 		= get_description('[DESCRIPTION]',$articles_info != null ? $articles_info->title : "");
		$this->data['keywords'] 		= get_keywords('[KEYWORDS]',$articles_info != null ? $articles_info->title : "");	    
		//end meta tag
		
		$this->data['tpl_file']		=	'html/lienhe';
		$this->load->view('layout/default',$this->data);
	}
	//page huong dan mua hang
	function huongdan()
	{
		$articles_info					= $this->html_model->get_articles_by_link('huong-dan-mua-hang');
		$this->data['articles_info'] 	= $articles_info;
		//meta tag
	    $this->data['title'] 			= get_title('[TITLE]',$articles_info != null ? $articles_info->title : "");
	    $this->data['description'] 		= get_description('[DESCRIPTION]',$articles_info != null ? $articles_info->title : "");
		$this->data['keywords'] 		= get_keywords('[KEYWORDS]',$articles_info != null ? $articles_info->title : "");	    
		//end meta tag
		
		$this->data['tpl_file']		=	'html/index';
		$this->load->view('layout/default',$this->data);
	}
}